package cn.infomany.code;

import cn.infomany.code.generate.CodeBaseListener;
import cn.infomany.code.generate.CodeParser;
import org.fxmisc.richtext.model.StyleSpansBuilder;

import java.util.Collection;
import java.util.Collections;

/**
 * 数据高亮监听器
 *
 * @author zjb
 * @date 2020/7/24
 */
public class CodeHighlightListener extends CodeBaseListener {

    private StyleSpansBuilder<Collection<String>> spansBuilder;

    public CodeHighlightListener(StyleSpansBuilder<Collection<String>> spansBuilder) {
        super();
        this.spansBuilder = spansBuilder;
    }


    @Override
    public void enterSE(CodeParser.SEContext ctx) {
        spansBuilder.add(Collections.singleton("scope"), 1);
    }

    @Override
    public void exitSE(CodeParser.SEContext ctx) {
        spansBuilder.add(Collections.singleton("scope"), 1);
    }

    @Override
    public void enterSSE(CodeParser.SSEContext ctx) {
        spansBuilder.add(Collections.singleton("scope"), 1);
    }

    @Override
    public void exitSSE(CodeParser.SSEContext ctx) {
        spansBuilder.add(Collections.singleton("scope"), 1);
    }

    @Override
    public void enterSimple(CodeParser.SimpleContext ctx) {
        super.enterSimple(ctx);
        spansBuilder.add(Collections.singleton("simple"), ctx.getText().length());
    }

    @Override
    public void enterStart(CodeParser.StartContext ctx) {
        super.enterStart(ctx);
        spansBuilder.add(Collections.singleton("start"), ctx.getText().length());
    }


    @Override
    public void enterSpeed(CodeParser.SpeedContext ctx) {
        super.enterSpeed(ctx);
        spansBuilder.add(Collections.singleton("speed"), ctx.getText().length());
    }


    @Override
    public void enterEnd(CodeParser.EndContext ctx) {
        super.enterEnd(ctx);
        spansBuilder.add(Collections.singleton("end"), ctx.getText().length());
    }


    @Override
    public void enterS(CodeParser.SContext ctx) {
        spansBuilder.add(Collections.singleton("scope"), 1);
    }

    @Override
    public void exitS(CodeParser.SContext ctx) {
        spansBuilder.add(Collections.singleton("scope"), 1);
    }

    @Override
    public void enterOp(CodeParser.OpContext ctx) {
        spansBuilder.add(Collections.singleton("op"), 1);
    }

    @Override
    public void enterComma(CodeParser.CommaContext ctx) {
        spansBuilder.add(Collections.singleton("op"), 1);
    }
}
